package com.woniuxy.student.controller;

import com.woniuxy.commons.entity.AnswerSheet;
import com.woniuxy.commons.entity.ResponseEntity;
import com.woniuxy.student.service.AnswerSheetService;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 曾令忠
 * @Description:
 * @Date: 2020/7/18 0018-下午 4:44
 */
@RestController
@RequestMapping("/answerSheet")
public class AnswerSheetController {
    @Resource
    AnswerSheetService answerSheetService;
    private static Logger logger = Logger.getLogger(AnswerSheetController.class);
    final static int stuno = 5;
    @GetMapping("/get/{paperId}")
    public ResponseEntity<AnswerSheet> getAnswerSheetByUserAndPaper(@PathVariable("paperId") Integer paperid) {
        AnswerSheet answerSheet = null;
        ResponseEntity<AnswerSheet> responseEntity = new ResponseEntity<>();
        try{
            answerSheet = answerSheetService.getAnswerSheetByUserid(stuno,paperid);
            responseEntity.setData(answerSheet);
            responseEntity.setCode(200);
        }catch (Exception e){
            logger.error(e);
            responseEntity.setCode(2);
        }

        return responseEntity;
    }

    @GetMapping("/getByStatus/{paperId}/{status}")
    public List<AnswerSheet> getAnswerSheetByStatusAndPaper(@PathVariable("paperId") Integer paperid, @PathVariable("status") Integer status) {
        return answerSheetService.getAnswerSheetByStatus(paperid,status);
    }

    @GetMapping("/get/{paperId}/{userid}")
    public AnswerSheet getAnswerSheetByRemoteUser(@PathVariable("paperId") Integer paperid,@PathVariable("userid") Integer userid){
        AnswerSheet answerSheet = answerSheetService.getAnswerSheetByUserid(userid,paperid);
        return answerSheet;
    }
}
